import 'package:get/get.dart';

/// 编辑卡片状态
class EditCardsState {
  /// 显示在首页的卡片列表
  RxList<HealthCardItem> displayedCards = <HealthCardItem>[].obs;

  /// 不显示在首页的卡片列表
  RxList<HealthCardItem> hiddenCards = <HealthCardItem>[].obs;

  /// 是否正在加载
  RxBool isLoading = false.obs;

  EditCardsState() {
    _initializeCards();
  }

  /// 初始化卡片数据（仅包含卡片数据模块中的小卡片）
  void _initializeCards() {
    // 只显示卡片数据模块中的小卡片
    displayedCards.value = [
      HealthCardItem(
        id: 'heart_rate',
        title: '心率',
        icon: 'assets/status/hr.png',
        isDisplayed: true,
      ),
      HealthCardItem(
        id: 'hrv',
        title: '心率变异性',
        icon: 'assets/status/hrv.png',
        isDisplayed: true,
      ),
      HealthCardItem(
        id: 'sleep',
        title: '睡眠',
        icon: 'assets/status/sleep.png',
        isDisplayed: true,
      ),
      HealthCardItem(
        id: 'blood_oxygen',
        title: '血氧饱和度',
        icon: 'assets/status/bloodOxygen.png',
        isDisplayed: true,
      ),
      HealthCardItem(
        id: 'activity',
        title: '活动',
        icon: 'assets/status/activity.png',
        isDisplayed: true,
      ),
      HealthCardItem(
        id: 'workout_records',
        title: '锻炼记录',
        icon: 'assets/status/traing.png',
        isDisplayed: true,
      ),
      HealthCardItem(
        id: 'physiological_cycle',
        title: '生理周期',
        icon: 'assets/status/cycle.png',
        isDisplayed: true,
      ),
    ];

    // 不显示在首页的卡片（初始为空）
    hiddenCards.value = [];
  }

  /// 移动卡片到显示列表
  void moveToDisplayed(HealthCardItem card) {
    if (hiddenCards.contains(card)) {
      hiddenCards.remove(card);
      card.isDisplayed = true;
      displayedCards.add(card);
    }
  }

  /// 移动卡片到隐藏列表
  void moveToHidden(HealthCardItem card) {
    if (displayedCards.contains(card)) {
      displayedCards.remove(card);
      card.isDisplayed = false;
      hiddenCards.add(card);
    }
  }

  /// 更新显示列表顺序
  void updateDisplayedOrder(List<HealthCardItem> newOrder) {
    displayedCards.value = newOrder;
  }
}

/// 健康卡片项目
class HealthCardItem {
  final String id;
  final String title;
  final String icon;
  bool isDisplayed;

  HealthCardItem({
    required this.id,
    required this.title,
    required this.icon,
    required this.isDisplayed,
  });

  /// 复制对象
  HealthCardItem copyWith({
    String? id,
    String? title,
    String? icon,
    bool? isDisplayed,
  }) {
    return HealthCardItem(
      id: id ?? this.id,
      title: title ?? this.title,
      icon: icon ?? this.icon,
      isDisplayed: isDisplayed ?? this.isDisplayed,
    );
  }
}
